﻿using System;
using Ewk.Math.Algebra.UnitTests.MatrixTests.NumericTests;
using Ewk.Math.ComputationTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests.MatrixSearchTests
{
    public abstract class GetColumnContainingTheMostZeroEntriesTestBase<T> : NumericTestBase<T>
        where T : struct, IComparable, IFormattable, IConvertible, IComparable<T>, IEquatable<T>
    {
        protected override Matrix<T> Matrix
        {
            get
            {
                return CreateMatrix(new[,]
                    {
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.One.Value, },
                    });
            }
        }

        [TestMethod]
        public void When_a_matrix_contains_no_zeroes_in_any_of_its_columns_Then_GetColumnContainingTheMostZeroEntries_returns_MatrixSearch_NotFound()
        {
            var i = Matrix.GetColumnContainingTheMostZeroEntries();
            Assert.AreEqual(MatrixSearch.NotFound, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_zeroes_in_only_the_first_column_Then_GetColumnContainingTheMostZeroEntries_returns_0()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetColumnContainingTheMostZeroEntries();
            Assert.AreEqual(0, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_zeroes_in_only_the_second_column_Then_GetColumnContainingTheMostZeroEntries_returns_1()
        {
            var matrix = Matrix;
            matrix[0, 1] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetColumnContainingTheMostZeroEntries();
            Assert.AreEqual(1, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_zeroes_in_the_first_and_the_second_column_Then_GetColumnContainingTheMostZeroEntries_returns_0()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;
            matrix[0, 1] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetColumnContainingTheMostZeroEntries();
            Assert.AreEqual(0, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_more_zeroes_in_the_second_column_than_in_the_first_column_Then_GetColumnContainingTheMostZeroEntries_returns_1()
        {
            var matrix = Matrix;
            matrix[0, 0] = Computable<T>.Factory.Zero.Value;
            matrix[0, 1] = Computable<T>.Factory.Zero.Value;
            matrix[1, 1] = Computable<T>.Factory.Zero.Value;

            var i = matrix.GetColumnContainingTheMostZeroEntries();
            Assert.AreEqual(1, i);
        }
    }
}